#!/bin/bash
#2017-09-23 1348
t=$(date +%m%d)
lt=$(date +%Y%m%d%H%M)
a="关闭防火墙"
b="开始防火墙"
ab="查看防火墙状态"
c="开放PSM70相关端口"
d="关闭PSM70相关端口"
cd="查看防火墙规则"
z="返回上一级"

temp="/work/temp"
bak_file="bakfile"
logn="logname"

echo "`pwd`"
function f_select(){
    PS3=-'请输入对应的数字选择要执行的操作！'
    select slt in ${a} ${b} ${ab} ${c} ${d} ${cd} ${z}; do
        case ${slt} in
        "${a}")
            logn=${a}
            cd firewall
            ./firewall.sh stop
            cd ..
            f_log
            break
            ;;
        "${b}")
            logn=${b}
            cd firewall
            ./firewall.sh start
            cd ..
            f_log
            break
            ;;
        "${ab}")
            logn=${ab}
            cd firewall
            ./firewall.sh status
            cd ..
            f_log
            break
            ;;
        "${c}")
            logn=${c}
            cd firewall
            ./fw_rule.sh addfirewall
            cd ..
            f_log
            break
            ;;
        "${d}")
            logn=${d}
            cd firewall
            ./fw_rule.sh delfirewall
            cd ..
            f_log
            break
            ;;
        "${cd}")
            logn=${cd}
            cd firewall
            ./fw_rule.sh fwrule
            cd ..
            f_log
            break
            ;;
        "${z}")
            echo 'bay,bay!!'
            exit
            ;;
        *)
            echo  "输入错误，请重新选择！"
            break
            ;;
        esac
    done
    f_select
}
function f_log(){
    if [ ! -d ${PWD}/log ]; then
        mkdir ${PWD}/log
        chmod 755 -R ${PWD}/log
    fi
    if [ ! -e ${PWD}/log/bak.log ]; then
        touch ${PWD}/log/bak.log
    fi
	#echo  "[" ` date '+%F %T %3N'`"]:">> ${PWD}/log/bak.log ##时间
    echo ${PWD}
    echo "["` date '+%F %T %3N'`"]:""选择了"${slt}  >> ${PWD}/log/bak.log
    echo "["` date '+%F %T %3N'`"]:""执行"${logn} >> ${PWD}/log/bak.log
}
f_select

